
// 手写reactive 实现A2 = A0+A1
let A0, A1, A2, observes;
let A2Dom = document.querySelector('#A2')

function A0Change(e) {
  A0.value = Number(e.target.value)
}

function A1Change(e) {
  A1.value = Number(e.target.value)
}

function reactive(obj) {
  return new Proxy(obj, {
    get(target, key, receiver) {
      return Reflect.get(target, key, receiver)
    },
    set(target, key, value, receiver) {
      let newValue = Reflect.set(target, key, value, receiver)
      update()
      return newValue
    }
  })
}


//作用update是A0,A1的订阅者
function update() {
  A2 = A0.value + A1.value
  A2Dom.innerText = A2
}


A0 = reactive({ value: null })
A1 = reactive({ value: null })


